######################################################
# RunAllScripts.R
# This file runs all scripts necessary to clean the survey data
# and merge in all additional data used in the analysis
# Contact Ryan Jablonski, r.s.jablonski@lse.ac.uk with questions
#
# Log
# Created 2018
# Edited for APSR replication 17 August 2023 by Ryan Jablonski
######################################################


rm(list=ls(all=TRUE))
working_dir="./APSR Replication/Merge and Clean Data/"
setwd(working_dir)


#check if output folder exists
if(!dir.exists("output")){
  dir.create("output")
}

# Organize and clean base survey file. Merge with school data and treatment variables.
source("./scripts/CleanSurveyData.R")

# create variables summarizing respondent knowledge
source("./scripts/CreateKnowledgeVariables.R")

# merge in some population estimates from WorldPop
source("./scripts/CreatePopulationVariables.R")

# merge in some poverty estimates from WorldPop
source("./scripts/CreatePovertyVariables.R")

# create all pre-specified covariates
source("./scripts/CreateCovariates.R")


# setup variables measuring distances between hometowns
source("./scripts/CreateDistanceVariables.R")

# setup some variables used for the quiz analysis
source("./scripts/SetupQuizData.R")

#setup citizen survey data files for Fig 2
source("./scripts/SetupCitizenSurveyData.R")

# final processing of files for analysis
source("./scripts/DoFinalProcessing.R")

# Uncomment this if you want to re-generate the power simulations
# WARNING: This will take many hours to run. 
# source("./scripts/DoPowerSimulations.R")

